﻿using System;
using System.IO;
using NLog;
using NLog.Config;

namespace RuTrackerLib
{
    public static class Log
    {
        public static void Initialize()
        {
            string assemblyLocation = new Uri(typeof (Log).Assembly.CodeBase).LocalPath;
            string folder = Path.GetDirectoryName(assemblyLocation);
            string logConfigLocation = Path.Combine(folder, @"NLog.config");
            LogManager.Configuration = new XmlLoggingConfiguration(logConfigLocation);
            Instance = LogManager.GetLogger("CommonLogger");
        }

        public static Logger Instance { get; private set; }

        public static void Debug(string message, params object[] args)
        {
            Instance.Debug(string.Format(message, args));
        }

        public static void Info(string message, params object[] args)
        {
            Instance.Info(string.Format(message, args));
        }

        public static void Warn(string message, params object[] args)
        {
            Instance.Warn(string.Format(message, args));
        }
        public static void Warn(Exception e, string message, params object[] args)
        {
            Instance.WarnException(string.Format(message, args), e);
        }

        public static void Error(Exception e)
        {
            Instance.ErrorException(e.Message, e);
        }

        public static void Error(string message, params object[] args)
        {
            Instance.Error(string.Format(message, args));
        }

        public static void Error(Exception e, string message, params object[] args)
        {
            Instance.ErrorException(string.Format(message, args), e);
        }
    }
}